package tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import coreSimulation.Passenger;
import coreSimulation.PassengerList;

/*
 * Test methods and constructor of the PassengerList class
 */
public class PassengerListTest {

	PassengerList pl;

	// Instantiate a passenger list
	@Before
	public void setUp() {
		pl = new PassengerList();
	}

	/*
	 * Test for IllegalArgumentException thrown by the PassengerList class when
	 * a null Passenger object is passed to the add method
	 */
	@Test(expected = IllegalArgumentException.class)
	public void testAddNull() {
		Passenger p = null;
		pl.add(p); // this should blow and raise an IllegalArgumentException up
					// as null values aren't allowed

	}

	/*
	 * Test for boolean value returned from the PassengerList add method
	 */
	@Test
	public void testAdd() {

		Passenger p = new Passenger("Bob Dobbs", "SA-12345678");
		assertTrue("The add() method of the PassengerList class failed",
				pl.add(p));

	}

	// test the getExcessCharges() method
	// which should return the total charges for all passengers in the list
	@Test
	public void testGetExcessCharges() {
		// clear the list
		pl.clear();

		// add passengers
		Passenger p1 = new Passenger("Person One", "SA-12345678");
		p1.addExcessCharge(100.50);
		pl.add(p1);

		Passenger p2 = new Passenger("Person Two", "SA-23456789");
		p2.addExcessCharge(200.50);
		pl.add(p2);

		// check returned totals match the sum of charges
		// for both passengers added
		assertEquals(pl.getExcessCharges(), 301, 0);
	}

}
